package A_review.review9_13;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Class131 {
    //TODO:2023/9/13  分割回文串
    List<List<String>>  result;
    LinkedList<String> path;
    public List<List<String>> partition(String s) {
        result=new ArrayList<>();
        path=new LinkedList<>();
       backTracking(s,0);
        return   result;
    }

    public  void  backTracking(String s,int start){
        if (start>s.length()-1){
            result.add(new ArrayList<>(path));
            return;
        }
        for (int i = start; i <s.length(); i++) {
            //TODO:2023/9/13 与之前的不同之处在于  需要加入一个回文判断
                if (isHuiWen(s,start,i)){
                    String str = s.substring(start, i + 1);
                    path.add(str);
                }else {
                    continue;
                }
                backTracking(s,i+1);
                path.removeLast();
        }
    }

    public  boolean isHuiWen(String s,int start,int end){

        for (int i = start,j=end; i <j ; i++,j--) {
            if (s.charAt(i)!=s.charAt(j)){
                return  false;
            }
        }
        return  true;

    }

    public static void main(String[] args) {

        Class131 class131 = new Class131();
        List<List<String>> aab = class131.partition("aab");
        System.out.println(aab.toString());
    }

}
